package com.zuilapsa.jmc.actions;

import com.zuilapsa.jmc.JmcException;
import com.zuilapsa.jmc.model.*;
import com.zuilapsa.jmc.userInterfaces.UserInterfaceSession;

public class ActionDel extends ActionNull {

	public void execute(UserInterfaceSession interfaceSession, String[] args)
			throws JmcException {
		if (args == null || args.length == 0) {
			interfaceSession.printMessageInfo(getHelpString());
		} else {
			String name = args[0];

			Level level = interfaceSession.getLevel();

			DefinitionWrapper dw = level.getSubDefinition(name);
			if (dw.isGlob()) {
				if (dw.isProperty()) {
					level.removeProperty(name);
					interfaceSession.printMessageInfo("Removed property: "
							+ name);
				} else if (dw.isLevel()) {
					level.removeLevel(name);
					interfaceSession.printMessageInfo("Removed level: " + name);
				}
			} else {
				interfaceSession
						.printMessageError("Only glob instances can be removed");
			}
		}
	}

	public String getHelpString() {
		return "Removes element if possible";
	}

}
